{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 14.4 \u5c06\u6d4b\u8bd5\u8f93\u51fa\u7528\u65e5\u5fd7\u8bb0\u5f55\u5230\u6587\u4ef6\u4e2d\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u95ee\u9898\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u4f60\u5e0c\u671b\u5c06\u5355\u5143\u6d4b\u8bd5\u7684\u8f93\u51fa\u5199\u5230\u5230\u67d0\u4e2a\u6587\u4ef6\u4e2d\u53bb\uff0c\u800c\u4e0d\u662f\u6253\u5370\u5230\u6807\u51c6\u8f93\u51fa\u3002"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u89e3\u51b3\u65b9\u6848\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u8fd0\u884c\u5355\u5143\u6d4b\u8bd5\u4e00\u4e2a\u5e38\u89c1\u6280\u672f\u5c31\u662f\u5728\u6d4b\u8bd5\u6587\u4ef6\u5e95\u90e8\u52a0\u5165\u4e0b\u9762\u8fd9\u6bb5\u4ee3\u7801\u7247\u6bb5\uff1a"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import unittest\n\nclass MyTest(unittest.TestCase):\n    pass\n\nif __name__ == '__main__':\n    unittest.main()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u8fd9\u6837\u7684\u8bdd\u6d4b\u8bd5\u6587\u4ef6\u5c31\u662f\u53ef\u6267\u884c\u7684\uff0c\u5e76\u4e14\u4f1a\u5c06\u8fd0\u884c\u6d4b\u8bd5\u7684\u7ed3\u679c\u6253\u5370\u5230\u6807\u51c6\u8f93\u51fa\u4e0a\u3002\n\u5982\u679c\u4f60\u60f3\u91cd\u5b9a\u5411\u8f93\u51fa\uff0c\u5c31\u9700\u8981\u50cf\u4e0b\u9762\u8fd9\u6837\u4fee\u6539 main() \u51fd\u6570\uff1a"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import sys\n\ndef main(out=sys.stderr, verbosity=2):\n    loader = unittest.TestLoader()\n    suite = loader.loadTestsFromModule(sys.modules[__name__])\n    unittest.TextTestRunner(out,verbosity=verbosity).run(suite)\n\nif __name__ == '__main__':\n    with open('testing.out', 'w') as f:\n        main(f)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### \u8ba8\u8bba\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u672c\u8282\u611f\u5174\u8da3\u7684\u90e8\u5206\u5e76\u4e0d\u662f\u5c06\u6d4b\u8bd5\u7ed3\u679c\u91cd\u5b9a\u5411\u5230\u4e00\u4e2a\u6587\u4ef6\u4e2d\uff0c\n\u800c\u662f\u901a\u8fc7\u8fd9\u6837\u505a\u5411\u4f60\u5c55\u793a\u4e86 unittest \u6a21\u5757\u4e2d\u4e00\u4e9b\u503c\u5f97\u5173\u6ce8\u7684\u5185\u90e8\u5de5\u4f5c\u539f\u7406\u3002"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "unittest \u6a21\u5757\u9996\u5148\u4f1a\u7ec4\u88c5\u4e00\u4e2a\u6d4b\u8bd5\u5957\u4ef6\u3002\n\u8fd9\u4e2a\u6d4b\u8bd5\u5957\u4ef6\u5305\u542b\u4e86\u4f60\u5b9a\u4e49\u7684\u5404\u79cd\u65b9\u6cd5\u3002\u4e00\u65e6\u5957\u4ef6\u7ec4\u88c5\u5b8c\u6210\uff0c\u5b83\u6240\u5305\u542b\u7684\u6d4b\u8bd5\u5c31\u53ef\u4ee5\u88ab\u6267\u884c\u4e86\u3002"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\u8fd9\u4e24\u6b65\u662f\u5206\u5f00\u7684\uff0cunittest.TestLoader \u5b9e\u4f8b\u88ab\u7528\u6765\u7ec4\u88c5\u6d4b\u8bd5\u5957\u4ef6\u3002\nloadTestsFromModule() \u662f\u5b83\u5b9a\u4e49\u7684\u65b9\u6cd5\u4e4b\u4e00\uff0c\u7528\u6765\u6536\u96c6\u6d4b\u8bd5\u7528\u4f8b\u3002\n\u5b83\u4f1a\u4e3a TestCase \u7c7b\u626b\u63cf\u67d0\u4e2a\u6a21\u5757\u5e76\u5c06\u5176\u4e2d\u7684\u6d4b\u8bd5\u65b9\u6cd5\u63d0\u53d6\u51fa\u6765\u3002\n\u5982\u679c\u4f60\u60f3\u8fdb\u884c\u7ec6\u7c92\u5ea6\u7684\u63a7\u5236\uff0c\n\u53ef\u4ee5\u4f7f\u7528 loadTestsFromTestCase() \u65b9\u6cd5\u6765\u4ece\u67d0\u4e2a\u7ee7\u627fTestCase\u7684\u7c7b\u4e2d\u63d0\u53d6\u6d4b\u8bd5\u65b9\u6cd5\u3002\nTextTestRunner \u7c7b\u662f\u4e00\u4e2a\u6d4b\u8bd5\u8fd0\u884c\u7c7b\u7684\u4f8b\u5b50\uff0c\n\u8fd9\u4e2a\u7c7b\u7684\u4e3b\u8981\u7528\u9014\u662f\u6267\u884c\u67d0\u4e2a\u6d4b\u8bd5\u5957\u4ef6\u4e2d\u5305\u542b\u7684\u6d4b\u8bd5\u65b9\u6cd5\u3002\n\u8fd9\u4e2a\u7c7b\u8ddf\u6267\u884c unittest.main() \u51fd\u6570\u6240\u4f7f\u7528\u7684\u6d4b\u8bd5\u8fd0\u884c\u5668\u662f\u4e00\u6837\u7684\u3002\n\u4e0d\u8fc7\uff0c\u6211\u4eec\u5728\u8fd9\u91cc\u5bf9\u5b83\u8fdb\u884c\u4e86\u4e00\u4e9b\u5217\u5e95\u5c42\u914d\u7f6e\uff0c\u5305\u62ec\u8f93\u51fa\u6587\u4ef6\u548c\u63d0\u5347\u7ea7\u522b\u3002\n\u5c3d\u7ba1\u672c\u8282\u4f8b\u5b50\u4ee3\u7801\u5f88\u5c11\uff0c\u4f46\u662f\u80fd\u6307\u5bfc\u4f60\u5982\u4f55\u5bf9 unittest \u6846\u67b6\u8fdb\u884c\u66f4\u8fdb\u4e00\u6b65\u7684\u81ea\u5b9a\u4e49\u3002\n\u8981\u60f3\u81ea\u5b9a\u4e49\u6d4b\u8bd5\u5957\u4ef6\u7684\u88c5\u914d\u65b9\u5f0f\uff0c\u4f60\u53ef\u4ee5\u5bf9 TestLoader \u7c7b\u6267\u884c\u66f4\u591a\u7684\u64cd\u4f5c\u3002\n\u4e3a\u4e86\u81ea\u5b9a\u4e49\u6d4b\u8bd5\u8fd0\u884c\uff0c\u4f60\u53ef\u4ee5\u6784\u9020\u4e00\u4e2a\u81ea\u5df1\u7684\u6d4b\u8bd5\u8fd0\u884c\u7c7b\u6765\u6a21\u62df TextTestRunner \u7684\u529f\u80fd\u3002\n\u800c\u8fd9\u4e9b\u5df2\u7ecf\u8d85\u51fa\u4e86\u672c\u8282\u7684\u8303\u56f4\u3002unittest \u6a21\u5757\u7684\u6587\u6863\u5bf9\u5e95\u5c42\u5b9e\u73b0\u539f\u7406\u6709\u66f4\u6df1\u5165\u7684\u8bb2\u89e3\uff0c\u53ef\u4ee5\u53bb\u770b\u770b\u3002"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.7.1"
    },
    "toc": {
      "base_numbering": 1,
      "nav_menu": {},
      "number_sections": true,
      "sideBar": true,
      "skip_h1_title": true,
      "title_cell": "Table of Contents",
      "title_sidebar": "Contents",
      "toc_cell": false,
      "toc_position": {},
      "toc_section_display": true,
      "toc_window_display": true
    }
  },
  "nbformat": 4,
  "nbformat_minor": 2
}